//Controller που ελεγχει το κουμπι update του dashboard. Ανανεωνει και θετει τα δεδομενα.
package Controllers;

import javax.swing.JOptionPane;

import DAO.javaconnect;
import com.mysql.jdbc.Statement;
import java.sql.Connection;
import java.sql.SQLException;

public class ChangePersonalData_Controller {

    public ChangePersonalData_Controller() {
    }

    public void changepersonaldata(String Name, String Surname, String Email, String Phone, String Pass, String Username, String OldUsername)
            throws ClassNotFoundException, SQLException {
        Connection conn = null;
        conn = javaconnect.connecrDb("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/nlr");
        if (Name.isEmpty() || Surname.isEmpty() || Email.isEmpty() || Phone.isEmpty() || Pass.isEmpty() || Username.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Empty Field");
        } else {
            //sql="UPDATE user SET `name`="+Name+",surname=[value-3],`username`=[value-4],`pass`=[value-5],`email`=[value-6],`phone`=[value-7],`noshop`=[value-8] WHERE 1"
            String sql;
            System.out.println(OldUsername);
            sql = "UPDATE user SET name='" + Name + "',surname='" + Surname + "',username='" + Username + "',pass='" + Pass + "',email='" + Email + "',phone='" + Phone + "' WHERE ID=1";
            Statement stmt;
            stmt = (Statement) conn.createStatement();
            stmt.executeUpdate(sql);
        }
    }
}
